public class Solution {
    // you need to treat n as an unsigned value
    //解法1：逐位比较
    public int hammingWeight(int n) {
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if (((n >>> i) & 1) == 1) count++;
        }
        return count;
    }
    //解法2：消1法
    public int hammingWeight2(int n) {
        int res = 0;
        while(n != 0) {
            res++;
            n &= n - 1;
        }
        return res;
    }
}